use async_trait::async_trait;
use serde_json::{Map, Value};

#[async_trait]
pub trait Callback: Send + Sync {
    async fn before_insert(
        &mut self,
        map_val: Map<String, Value>,
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<Map<String, Value>> {
        Ok(map_val)
    }
    async fn before_update(
        &mut self,
        map_val: Map<String, Value>,
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<Map<String, Value>> {
        Ok(map_val)
    }
    async fn before_save(
        &mut self,
        map_val: Map<String, Value>,
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<Map<String, Value>> {
        Ok(map_val)
    }
    async fn before_delete(
        &mut self,
        _ids: &[u64],
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<()> {
        Ok(())
    }
    async fn after_save(
        &mut self,
        _map_val: Map<String, Value>,
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<()> {
        Ok(())
    }
    async fn after_delete(
        &mut self,
        _ids: &[u64],
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<()> {
        Ok(())
    }
    async fn after_find(
        &mut self,
        map_val: Map<String, Value>,
        _tx: &mut sqlx::Transaction<'_, sqlx::MySql>,
    ) -> anyhow::Result<Map<String, Value>> {
        Ok(map_val)
    }
}
